<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>二维码管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 基础信息管理 <span class="c-gray en">&gt;</span> 二维码管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container" id="app">
	<div class="text-c">
		<form id="queryForm">
			<span class="select-box inline" v-if="isAdmin">
				<select class="select" id="companyid" name="company.companyid"></select>
			</span>
			<span class="select-box inline">
				<select class="select" id="status" name="status"></select>
			</span>
			<button class="btn btn-success" type="button" v-on:click="query()"><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
		</form>
		<a href="javascript:;" onclick="member_add('申请二维码','authinfo-group-add.html','','510')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 申请二维码</a></span></div>
	</div>
	<div class="mt-20">
		<table id="list" class="table table-border table-bordered table-hover table-bg table-sort">
		</table>
	</div>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="DataTables/datatables.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="js/jquery.base64.js"></script>
<script type="text/javascript" src="js/vue.js" charset="utf-8"></script>
<script type="text/javascript">
/*组-添加*/
function member_add(title,url,w,h){
	layer_show(title,url,w,h);
}
/*组-查看*/
function member_show(title,url,id,w,h){
	layer_show(title,url,w,h);
}
/*组-编辑*/
function member_edit(title,url,id,w,h){
	layer_show(title,url + "?id=" + id,w,h);
}
</script> 
<script type="text/javascript">
	var vm = new Vue({
		el : "#app",
		data : {
			msg : "",
			isAdmin : true
		},
		//在实例初始化之后，数据观测 (data observer) 和 event/watcher 事件配置之前被调用。
		beforeCreate:function(){
			console.log('beforeCreate');
		},
		/* 在实例创建完成后被立即调用。
		在这一步，实例已完成以下的配置：数据观测 (data observer)，属性和方法的运算，watch/event 事件回调。
		然而，挂载阶段还没开始，$el 属性目前不可见。 */
		created	:function(){
			console.log('created');
		},
		//在挂载开始之前被调用：相关的渲染函数首次被调用
		beforeMount : function(){
			console.log('beforeMount');
	
		},
		//el 被新创建的 vm.$el 替换, 挂在成功	
		mounted : function(){
			console.log('mounted');
		
		},
		//数据更新时调用
		beforeUpdate : function(){
			console.log('beforeUpdate');
				
		},
		//组件 DOM 已经更新, 组件更新完毕 
		updated : function(){
			console.log('updated');
				
		},
		methods: {
			query: function(){
				table.draw();
			}
		}
	});
	
	$(function(){
		$.ajax({
			 url: ipAddress + 'base/company/getList',
			data: {
				order: "ordercode"
			},
			beforeSend: function (request) {
				request.setRequestHeader("Authorization", "Bearer " + getToken());
			},
			method:'GET',
			success:function (data,status,request) {
				console.log(data);
				$("#companyid").append("<option value>请选择分公司</option>");
				for(var i = 0; i < data.length; i ++){
					$("#companyid").append("<option value='" + data[i].companyid + "'>" + data[i].companyname + "</option>");
				}
			},
			error:function (request, msg, obj) {
				var respTxtObj = JSON.parse(request.responseText);
				console.log(respTxtObj);
				console.log(respTxtObj.error);
				console.log(respTxtObj.error_description);
			}
		});
		
		$.ajax({
			 url: ipAddress + 'base/qrcodeApplication/getStatus',
			data: {
			},
			beforeSend: function (request) {
				request.setRequestHeader("Authorization", "Bearer " + getToken());
			},
			method:'GET',
			success:function (data,status,request) {
				console.log(data);
				$("#status").append("<option value>请选择状态</option>");
				for(let key in data){
					$("#status").append("<option value='" + key + "'>" + data[key] + "</option>");
				}
			},
			error:function (request, msg, obj) {
				var respTxtObj = JSON.parse(request.responseText);
				console.log(respTxtObj);
				console.log(respTxtObj.error);
				console.log(respTxtObj.error_description);
			}
		});
	});
	
	var table = $('#list').DataTable({
		language: {
			url: 'static/h-ui.admin/js/de_DE.txt'
		},
		lengthMenu: [[5, 10, 25, 50, 100], [5, 10, 25, 50, 100]],//设置每页显示数据条数的下拉选项
		displayLength: 100, //每页初始显示5条记录
		stateSave: true,
		searching: false,
		processing: true,
		serverSide: true,
		order: [[1, 'asc']],
		ajax: {
			 url: ipAddress + 'base/qrcodeApplication/getTablePage',
			type: 'GET',
			data: function ( data ) {
				var param = {};
				var userInfo = getUserInfo();
				var page = data.start == 0 ? 0 : data.start / data.length;
				var size = data.length;
				var order = data.columns[data.order[0].column].data + " " + data.order[0].dir;
				param.draw = data.draw;
				param.page = page;
				param.size = size;
				param.order = order;
				if (!vm.isAdmin) {
					param['company.companyid'] = userInfo.company.companyid;
				}
				var formData = $("#queryForm").serializeArray();//把form里面的数据序列化成数组
				formData.forEach(function (e) {
					if(e.value != ''){
						param[e.name] = e.value;
					}
				});
				return param;
			}
		},
		columns: [
			{title: '<input type="checkbox"/>',
				render: function(data, type, row, meta) {
					return "<input type='checkbox' name='ids' value='" + row.id +"'/>";
				}
			},
			{title: '分公司', name: 'companyname', data: 'company.companyname', defaultContent: '无'},
			{title: '二维码类型', name: 'qrcodeType', data: 'qrcodeType', defaultContent: '无',
				render: function(data, type, row, meta) {
					return row.qrcodeType == null ? '无' : row.qrcodeType.name + '(' + row.qrcodeType.type + ')';
				}
			},
			{title: '数量', name: 'amount', data: 'amount', defaultContent: ''},
			{title: '备注', name: 'comment', data: 'comment', defaultContent: ''},
			{title: '申请人', name: 'applicant', data: 'applicant', defaultContent: ''},
			{title: '申请时间', name: 'applicationTime', data: 'applicationTime', defaultContent: ''},
			{title: '审核人', name: 'auditor', data: 'auditor', defaultContent: ''},
			{title: '审核时间', name: 'auditTime', data: 'auditTime', defaultContent: ''},
			{title: '确认人', name: 'confirmer', data: 'confirmer', defaultContent: ''},
			{title: '确认时间', name: 'confirmTime', data: 'confirmTime', defaultContent: ''},
			{title: '状态', name: 'status', data: 'status', defaultContent: '无',
				render: function(data, type, row, meta) {
					return row.status == 1 ? '提交' : row.status == 2 ? '审核通过' : row.status == 3 ? '审核未通过' : row.status == 4 ? '印制' : row.status == 5 ? '完成' : '无';
				}
			},
			{title: '操作', name: 'operations', defaultContent: '',
				render: function(data, type, row, meta) {
					var operations;
					var op_edit = "<a title=\"编辑\" href=\"javascript:;\" onclick=\"app_edit('编辑','authinfo-user-update.html','" + row.id + "','','510')\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont Hui-iconfont-edit\"></i>编辑</a>";
					var op_audit = "<a title=\"审核\" href=\"javascript:;\" onclick=\"app_audit('审核','authinfo-user-update.html','" + row.id + "','','510')\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont Hui-iconfont-shenhe-weitongguo\"></i>审核</a>";
					var op_print = "<a title=\"印制\" href=\"javascript:;\" onclick=\"app_print(this,'" + row.id + "')\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont Hui-iconfont-dayinji\"></i>印制</a>";
					var op_confirm = "<a title=\"确认\" href=\"javascript:;\" onclick=\"app_confirm(this,'" + row.id + "')\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont Hui-iconfont-shenhe-tongguo\"></i>确认</a>";
					var op_del = "<a title=\"删除\" href=\"javascript:;\" onclick=\"app_del(this,'" + row.id + "')\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont Hui-iconfont-del3\"></i>删除</a>";
					if(hasRole("ADMIN") || hasRole("GROUP")) {
						if(row.status == 1) {
							operations = op_audit;
						} else if(row.status == 2) {
							operations = op_print;
						}
					} else if(hasRole("COMPANY")) {
						if(row.status == 1) {
							operations = op_edit + op_del;
						} else if(row.status == 4) {
							operations = op_confirm;
						}
					}
					return operations;
				}
			}
		],
		columnDefs: [
			{"orderable":false,"targets":[0,6]}
		]
	});
</script>
</body>
</html>